{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 32,
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'x' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mNameError\u001B[0m                                 Traceback (most recent call last)",
      "Input \u001B[1;32mIn [32]\u001B[0m, in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[1;32m----> 1\u001B[0m \u001B[38;5;28;01mclass\u001B[39;00m \u001B[38;5;21;01mPoint\u001B[39;00m:\n\u001B[0;32m      2\u001B[0m     \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21m__init__\u001B[39m(\u001B[38;5;28mself\u001B[39m, x, y):\n\u001B[0;32m      3\u001B[0m         \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m__x \u001B[38;5;241m=\u001B[39m x\n",
      "Input \u001B[1;32mIn [32]\u001B[0m, in \u001B[0;36mPoint\u001B[1;34m()\u001B[0m\n\u001B[0;32m      6\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21m__str__\u001B[39m(\u001B[38;5;28mself\u001B[39m):\n\u001B[0;32m      7\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mPoint(\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m__x\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m, \u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m__y\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m)\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m----> 9\u001B[0m \u001B[38;5;129m@x\u001B[39m\u001B[38;5;241m.\u001B[39msetter\n\u001B[0;32m     10\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mx\u001B[39m(\u001B[38;5;28mself\u001B[39m, value):\n\u001B[0;32m     11\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m__x \u001B[38;5;241m=\u001B[39m value\n\u001B[0;32m     13\u001B[0m \u001B[38;5;129m@property\u001B[39m\n\u001B[0;32m     14\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mx\u001B[39m(\u001B[38;5;28mself\u001B[39m):\n",
      "\u001B[1;31mNameError\u001B[0m: name 'x' is not defined"
     ]
    }
   ],
   "source": [
    "class Point:\n",
    "    def __init__(self, x, y):\n",
    "        self.__x = x\n",
    "        self.__y = y\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"Point({self.__x}, {self.__y})\"\n",
    "\n",
    "    @x.setter\n",
    "    def x(self, value):\n",
    "        self.__x = value\n",
    "\n",
    "    @property\n",
    "    def x(self):\n",
    "        return self.__x\n",
    "\n",
    "p = Point(2, 3)\n",
    "print(p)\n",
    "print(p.x)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'x' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mNameError\u001B[0m                                 Traceback (most recent call last)",
      "Input \u001B[1;32mIn [30]\u001B[0m, in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[0;32m      1\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m \u001B[38;5;21;01mmath\u001B[39;00m\n\u001B[1;32m----> 3\u001B[0m \u001B[38;5;28;01mclass\u001B[39;00m \u001B[38;5;21;01mPoint\u001B[39;00m:\n\u001B[0;32m      4\u001B[0m     \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21m__init__\u001B[39m(\u001B[38;5;28mself\u001B[39m, x, y):\n\u001B[0;32m      5\u001B[0m         \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m__x \u001B[38;5;241m=\u001B[39m x\n",
      "Input \u001B[1;32mIn [30]\u001B[0m, in \u001B[0;36mPoint\u001B[1;34m()\u001B[0m\n\u001B[0;32m      5\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m__x \u001B[38;5;241m=\u001B[39m x\n\u001B[0;32m      6\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m__y \u001B[38;5;241m=\u001B[39m y\n\u001B[1;32m----> 8\u001B[0m \u001B[38;5;129m@x\u001B[39m\u001B[38;5;241m.\u001B[39msetter\n\u001B[0;32m      9\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mx\u001B[39m(\u001B[38;5;28mself\u001B[39m, value):\n\u001B[0;32m     10\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m__x \u001B[38;5;241m=\u001B[39m value\n\u001B[0;32m     12\u001B[0m \u001B[38;5;129m@property\u001B[39m\n\u001B[0;32m     13\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mx\u001B[39m(\u001B[38;5;28mself\u001B[39m):\n",
      "\u001B[1;31mNameError\u001B[0m: name 'x' is not defined"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "class Point:\n",
    "    def __init__(self, x, y):\n",
    "        self.__x = x\n",
    "        self.__y = y\n",
    "\n",
    "    @x.setter\n",
    "    def x(self, value):\n",
    "        self.__x = value\n",
    "\n",
    "    @property\n",
    "    def x(self):\n",
    "        return self.__x\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"Point({self.__x}, {self.__y})\"\n",
    "\n",
    "    def getDistance(self, other):\n",
    "        w = self.__x - other.__x\n",
    "        h = self.__y - other.__y\n",
    "        return math.sqrt(w**2 + h**2)\n",
    "\n",
    "class Circle:\n",
    "    def __init__(self, o, r):\n",
    "        self.o = o\n",
    "        self.r = r\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"Circle({self.o}, {self.r})\"\n",
    "\n",
    "    def getArea(self):\n",
    "        return math.pi * self.r**2\n",
    "\n",
    "    def getPerimeter(self):\n",
    "        return math.pi * self.r * 2\n",
    "\n",
    "class Point3D:\n",
    "    def __init__(self, x, y, z):\n",
    "        self.x = x\n",
    "        self.y = y\n",
    "        self.z = z\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"Point3D({self.x}, {self.y}, {self.z})\"\n",
    "\n",
    "    def getDistance(self, other):\n",
    "        w = self.x - other.x\n",
    "        h = self.y - other.y\n",
    "        s = self.z - other.z\n",
    "        return math.sqrt(w**2 + h**2 + s**2)\n",
    "\n",
    "class Sphere(Point3D):\n",
    "    def __init__(self, x, y, z, r):\n",
    "        super().__init__(x, y, z)\n",
    "        self.r = r\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"Sphere({super().__str__()}, {self.r})\"\n",
    "\n",
    "    def getArea(self):\n",
    "        return 4 * math.pi * self.r**2\n",
    "\n",
    "    def getVolume(self):\n",
    "        return 4 / 3 * math.pi * self.r**3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sphere(Point3D(2, 3, 5), 7)\n",
      "615.7521601035994\n",
      "1436.7550402417319\n"
     ]
    }
   ],
   "source": [
    "s = Sphere(2, 3, 5, 7)\n",
    "print(s)\n",
    "print(s.getArea())\n",
    "print(s.getVolume())"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Point(2, 3)\n",
      "Point(5, 7)\n",
      "the distance from Point(2, 3) to Point(5, 7) is 5.0\n"
     ]
    }
   ],
   "source": [
    "p1 = Point(2, 3)\n",
    "p2 = Point(5, 7)\n",
    "print(p1)\n",
    "print(p2)\n",
    "print(f\"the distance from {p1} to {p2} is {p1.getDistance(p2)}\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Circle(Point(2, 3), 7)\n",
      "153.93804002589985\n",
      "43.982297150257104\n",
      "Circle(Hello, World, 7)\n",
      "153.93804002589985\n",
      "43.982297150257104\n"
     ]
    }
   ],
   "source": [
    "p = Point(2, 3)\n",
    "c = Circle(p, 7)\n",
    "print(c)\n",
    "print(c.getArea())\n",
    "print(c.getPerimeter())\n",
    "c2 = Circle(\"Hello, World\", 7)\n",
    "print(c2)\n",
    "print(c2.getArea())\n",
    "print(c2.getPerimeter())"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}